<?php
namespace Apps\BoxSns\Model;

use Think\Model;

class SnsMessageRecordModel extends \BaseModel
{

    /**********消息汇总*******/
    public function record($from_id, $to_id, $box_id)
    {
        $row1 = array(
            'user_id' => $from_id > $to_id ? $to_id : $from_id,
            'to_user_id' => $from_id > $to_id ? $from_id : $to_id,
            'now_time' => time(),
            'box_id' => $box_id,
        );
        if ($this->where("box_id='$box_id'")->field("id")->find()) {
            $r1 = $this->where("box_id='$box_id'")->setInc("count");
            $r2 = $this->where("box_id='$box_id'")->save(array('now_time' => time()));
        } else {
            $r1 = $this->add($row1);
        }
        if ($r1) {
            return true;
        } else {
            return false;
        }

    }


}
 